import { showToast, showConfirmDialog } from 'vant';
import BusinessStore from '@/stores/business';
import AddressStore from '@/stores/address';
import CartStore from '@/stores/cart';

const success = (message,onClose = () => {},duration = 1500) =>
{
    showToast({
        type:'success',
        message,
        duration,
        onClose
    });
}

const fail = (message,onClose = () => {},duration = 1500) =>
{
    showToast({
        type:'fail',
        message,
        duration,
        zIndex:9999,
        onClose
    });
}

export default {
    install(app)
    {
        // 实例化
        const BusinessInit = BusinessStore();
        const AddressInit = AddressStore();
        const CartInit = CartStore();

        // 从状态管理提取business属性，保持响应式
        const { business } = storeToRefs(BusinessInit);
        // 确认订单的收货地址
        const { address } = storeToRefs(AddressInit);
        // 立即购买的确认订单数据
        const { cart } = storeToRefs(CartInit);

        // 定义全局属性
        app.config.globalProperties.$success = success;
        app.config.globalProperties.$fail = fail;
        app.config.globalProperties.$confirm = showConfirmDialog;

        app.config.globalProperties.$business = business;
        app.config.globalProperties.$address = address;
        app.config.globalProperties.$cart = cart;
    }
}